
/**
 * Universidad del Valle de Guatemala
 * Algoritmos y estructuras de datos
 * Karen Tojin   08091
 * Fecha: 01 de octubre de 2009
 * Descricion: Clase nodo para los árboles 2-3
 */
/**
 *
 * @author karenAndy
 */
public class Node<T> {

    private T element1 = null, element2 = null;
    boolean complete = false, areElements = false;
    private Node<T> father, left, right, center;

    public Node(T newElement) {
        this.father = null;
        this.left = null;
        this.right = null;
        this.center = null;
        if (element1 == null) {
            element1 = newElement;
        } else {
            element2 = newElement;
        }
    }

    public void setElement1(T element) {
        this.element1 = element;
    }

    public T getElement1() {
        return element1;
    }

    public void setElement2(T element) {
        element2 = element;
    }

    public T getElement2() {
        return element2;
    }

    public void setLeft(Node left) {
        this.left = left;
    }

    public Node getLeft() {
        return left;
    }

    public void setRight(Node right) {
        this.right = right;
    }

    public Node getRight() {
        return right;
    }

    public void setFather(Node father) {
        this.father = father;
    }

    public Node getFather() {
        return father;
    }

    public void setCenter(Node center) {
        this.center = center;
    }

    public Node getCenter() {
        return center;
    }

    public void CheckTree() {
        if (left != null && right != null && center != null && element1 != null && element2 != null) {
            complete = true;
        } else {
            complete = false;
        }

        if (element1 != null && element2 != null) {
            areElements = true;
        } else {
            areElements = false;
        }
    }

    @Override
    public String toString() {
        String set = "";

        if (left != null) {
            set += (left.toString());
        }

        if (element1 != null) {
            set += (" " + element1);
        }

        if (center != null) {
            set += (center.toString());
        }

        if (element2 != null) {
            set += (" " + element2);
        }

        if (right != null) {
            set += (right.toString());
        }

        return set;
    }
}
